package com.ccy.search.web;

import com.ccy.search.service.SearchEsModelService;
import com.ccy.search.vo.SearchParam;
import com.ccy.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;

/**
 * @author coder_ccy
 * @date 2022/7/25 11:28
 */

@Controller
public class IndexController {


    @Autowired
    private SearchEsModelService searchEsModelService;


    @GetMapping({"","/index.html"})
    public String index(@RequestBody( required = false) SearchParam searchParam, Model model) throws IOException {

        SearchResult result = searchEsModelService.search(searchParam);

        model.addAttribute("result",result);


        return "index";
    }
}
